//
//  U9ChangyanManager.m
//  iMobile
//
//  Created by baken on 2017/1/10.
//  Copyright © 2017年 MyApp. All rights reserved.
//

#import "U9ChangyanManager.h"
#import "U9ChangYanCommentModel.h"

@implementation U9ChangyanManager

+ (void)getChangyanTopicIDWithSourceID:(NSString *)topicSourceID andCompletionHandle:(void(^)(U9ChangYanCommentModel *model, NSError *error))complete{
    
    [ChangyanSDK loadTopic:@"" topicTitle:nil topicSourceID:topicSourceID pageSize:nil hotSize:nil orderBy:nil style:nil depth:nil subSize:nil completeBlock:^(CYStatusCode statusCode, NSString *responseStr) {
        NSData *resData = [[NSData alloc] initWithData:[responseStr dataUsingEncoding:NSUTF8StringEncoding]];
        id dict = [NSJSONSerialization JSONObjectWithData:resData options:NSJSONReadingMutableLeaves error:nil];
        U9ChangYanCommentModel *model = [U9ChangYanCommentModel new];
        model.topic_id = [NSString stringWithFormat:@"%@",dict[@"topic_id"]];
        model.cmt_sum = [NSString stringWithFormat:@"%@",dict[@"cmt_sum"]];
        
        NSError *error = nil;
        if (statusCode != 0) {
            error = [self createError:@"评论信息获取失败"];
        }
        complete(model,error);
    }];
}


+ (void)getChangyanCommentsListWithTopicID:(NSString *)topicID andPageNum:(NSString *)num andCompletionHandle:(void (^)(U9ChangYanCommentModel *model, NSError *error))complete{
    [ChangyanSDK getTopicComments:topicID pageSize:nil pageNo:num orderBy:nil style:nil depth:nil subSize:nil completeBlock:^(CYStatusCode statusCode, NSString *responseStr) {
        NSData *resData = [[NSData alloc] initWithData:[responseStr dataUsingEncoding:NSUTF8StringEncoding]];
        id dict = [NSJSONSerialization JSONObjectWithData:resData options:NSJSONReadingMutableLeaves error:nil];
        U9ChangYanCommentModel *model = [U9ChangYanCommentModel mj_objectWithKeyValues:dict];
        NSError *error = nil;
        if (statusCode != 0) {
            error = [self createError:@"评论信息获取失败"];
        }
        complete(model,error);
    }];
}


+ (void)commentNewsWithContent:(NSString *)content andTopicID:(NSString *)topicID andReplyID:(NSString *)replyID andCompletionHandle:(void (^)(NSError *error))complete{
    [ChangyanSDK submitComment:topicID content:content replyID:replyID score:nil appType:40 picUrls:nil metadata:nil completeBlock:^(CYStatusCode statusCode, NSString *responseStr) {
        NSData *resData = [[NSData alloc] initWithData:[responseStr dataUsingEncoding:NSUTF8StringEncoding]];
        id dict = [NSJSONSerialization JSONObjectWithData:resData options:NSJSONReadingMutableLeaves error:nil];
        NSError *error = nil;
        if ([dict[@"error_code"] longLongValue] != 0) {
            error = [self createError:@"评论信息获取失败"];
        }
        complete(error);
    }];
    
}





@end
